<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <input class="user" type="text">
    <br>
    <input class="pwd" type="text">
    <br>
    <button>登陆</button>

    <script>

        const oBtn = document.querySelector('button') ;
        const oUser = document.querySelector('.user') ;
        const oPwd = document.querySelector('.pwd') ;

        const cookies = document.cookie ;    // username=yy; userpwd=123

        const arr = cookies.split('; ') ;
        console.log(arr);


        const res = arr.map( v => {
            let arr = v.split('=') ;
            let obj = {} ;
            obj.a = arr[0] ;
            obj.b = arr[1] ;
            return obj
        })

        console.log(res);
        
        // [
        //     {
        //         a : username ,
        //         b : yy 
        //     } , 
        //     {
        //         a : userpwd ,
        //         b : 123 
        //     }
        // ]





        oBtn.onclick = function() {
            // 获取用户名和密码
            const user = oUser.value ;
            const pwd = oPwd.value ;

            // some方法

            // 判断用户名是否正确   找到满足条件的数据   filter
            const r = res.filter( v => v.b === user) ;
            console.log(r);
            if(r.length === 0) {
                alert('用户名不存在') ;
            } else {
                // 确认密码
                const miMa = res.filter( v => v.b === pwd) ;
                if(miMa.length > 0) {
                    alert('ok') ;
                } else {
                    alert('密码错误') ;
                }
            }

        }

    </script>
    
</body>
</html>